<?php
/**
 * 当前病例对应的用户信息
 */
class M_DiagnosisUserBase extends ModuleBase{

	/**
	 *
	 * @param DiagnosisUserBase $DiagnosisUserBase
	 * @return DiagnosisUserBase
	 */
	public function insert($DiagnosisUserBase=null){
		if($DiagnosisUserBase===null){
			return null;
		}

		$o=new DiagnosisUserBase($DiagnosisUserBase);
		/**
		 *
		 * @todo Ini
		 */

		$o->Id=$this->db->guid();

		if($this->db->insert('DiagnosisUserBase',$o->__modetoarray())>0){
			//$this->_dishsave('DiagnosisUserBase', $o->Id, $o);
		}
		else{

			$o->Id=null;

		}
		return $o;
	}

	/**
	 *
	 * @param DiagnosisUserBase $DiagnosisUserBase
	 * @return int
	 */
	public function update($DiagnosisUserBase=null){
		if($DiagnosisUserBase===null){
			return null;
		}

		$o=new DiagnosisUserBase($DiagnosisUserBase);/**
		*
		* @todo Condition
		*/
		
		if($this->db->update('DiagnosisUserBase',$o->__modetoarray(array('Name'=>$o->Name,'UserSex'=>$o->UserSex,'BirthDay'=>$o->BirthDay,'People'=>$o->People,'Email'=>$o->Email,'Mobile'=>$o->Mobile)),array('DiagnosisId'=>$o->DiagnosisId))>0){
			//$this->_dishsave('DiagnosisUserBase', $this->Id, $DiagnosisUserBase);
			return 1;
		}else{
			return 0;
		}
	}

	/**
	 * @param DiagnosisUserBase $DiagnosisUserBase
	 * return int
	 */
	public function delete($DiagnosisUserBase=null){
		if($DiagnosisUserBase===null||!isset($DiagnosisUserBase->Id)||empty($DiagnosisUserBase->Id)){
			return null;
		}
		
		$this->db->delete('DiagnosisUserBase',array('Id'=>$this->Id));
		return $this->db->delete('DiagnosisUserBase',array('Id'=>$this->Id));
	}

	/**
	 * @param DiagnosisUserBase $DiagnosisUserBase
	 */
	public function single($DiagnosisUserBase=null){
		if($DiagnosisUserBase===null||!isset($DiagnosisUserBase->Id)||empty($DiagnosisUserBase->Id)){
			return null;
		}
		$o=$this->_dishread('DiagnosisUserBase',$this->Id);

		if($o===null){
			foreach($this->db->select('DiagnosisUserBase',array('Id'=>$this->Id)) as $i){
				$o=new DiagnosisUserBase($i);break;
			}
			if($o!==null){
				$this->_dishsave('DiagnosisUserBase',$this->Id,$o);
			}
		}
		return $o;
	}

	/**
	 *
	 * @param object {'PageIndex':0,'PageSize':20}
	 */
	public function arraylist($search=null){
		$li=array();
		$cond=array();

		$PageIndex=0;$PageSize=20;
		if($search!==null){
			if(is_numeric($search->PageIndex)){
				$PageIndex=$search->PageIndex;
			}
			if(is_numeric($search->PageSize)){
				$PageSize=$search->PageSize;
			}
		}

		foreach($this->db->select('DiagnosisUserBase',$cond,'',array(intval($PageIndex),intval($PageSize))) as $i){
			$li=new DiagnosisUserBase();
		}
		return $li;
	}
}

?>